package com.snake.springboot.authority.service.assembler;

import com.snake.springboot.authority.api.model.AuthRoleMenuModel;
import com.snake.springboot.authority.api.request.AuthRoleMenuSave;
import com.snake.springboot.authority.dao.mybatis.entity.AuthRoleMenuDO;
import org.snake.common.utils.ListUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类 {@code AuthRoleMenuAssembler}  <br> .
 * <p>角色与菜单关系组装器
 * 创建时间：2024/5/27 16:26
 *
 * @author Yzhui
 * @see
 */
public class AuthRoleMenuAssembler {

    public static AuthRoleMenuDO assembleAuthRoleMenuDO(AuthRoleMenuModel model) {
        AuthRoleMenuDO entity = new AuthRoleMenuDO(model.getRoleId(), model.getMenuId());
        entity.setMenuName(model.getMenuName());
        entity.setSystemId(model.getSystemId());
        return entity;
    }

    public static AuthRoleMenuModel assembleAuthRoleMenuModel(AuthRoleMenuDO entity) {
        AuthRoleMenuModel model = new AuthRoleMenuModel(entity.getRoleId(), entity.getMenuId());
        return model;
    }

    public static List<AuthRoleMenuDO> assembleAuthRoleMenuDOList(List<AuthRoleMenuModel> modelList) {
        List<AuthRoleMenuDO> entityList = ListUtils.copy(modelList, AuthRoleMenuDO.class);
        return entityList;
    }

    public static List<AuthRoleMenuModel> assembleAuthRoleMenuModelList(List<AuthRoleMenuDO> entityList) {
        List<AuthRoleMenuModel> modelList = ListUtils.copy(entityList, AuthRoleMenuModel.class);
        return modelList;
    }

    public static List<AuthRoleMenuDO> createAuthRoleMenuDOList(AuthRoleMenuSave params) {
        List<AuthRoleMenuDO> entityList = new ArrayList<>();
        AuthRoleMenuDO entity;
        for(String menuId :params.getMenuIds()){
            entity = new AuthRoleMenuDO();
            entity.setRoleId(params.getRoleId());
            entity.setMenuId(menuId);
            entityList.add(entity);
        }
        return entityList;
    }

}
